﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_ControlXacMinhNVDoiGia : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadGrid();
        }
    }
    void ShowMessageBox(string text)
    {
        MessageBox.Text = text;
        MessageBox.ShowOnPageLoad = true;
    }
    protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        LoadGrid();
    }
    protected void grvChangePrice_PageIndexChanging1(object sender, GridViewPageEventArgs e)
    {
        grvChangePrice.PageIndex = e.NewPageIndex;
        LoadGrid();
    }
    void LoadGrid()
    {
        dt = new ClassExecute.ClassExecute();
        try
        {
            DataTable db = dt.Get_Data_DataTable(str, ref error, "[ls_getChangePriceTranList4Post]", CommandType.StoredProcedure,
                new SqlParameter("@sitecode", Session["sitecode"].ToString()));
            if (db.Rows.Count == 0)
            {
                grvChangePrice.DataSource = null;
               
            }
            else
            {
                grvChangePrice.DataSource = db;
            }
            grvChangePrice.DataBind();
        }
        catch (Exception ex)
        {

            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            dt.WriteErrorLog(Server.MapPath(webapp4U.Globals.LogUrl()), ex.Message, method);
        }
    }
    protected void grvChangePrice_RowCommand1(object sender, GridViewCommandEventArgs e)
    {
        dt = new ClassExecute.ClassExecute();
        try
        {
            if (e.CommandName == "chon")
            {
                GridViewRow grv = ((Control)e.CommandSource).NamingContainer as GridViewRow;
                Label lblMaSo = (Label)grv.FindControl("lblMaSo");

                bool kq = dt.ExecuteSQl_bool(str, CommandType.StoredProcedure, "[ls_postChangePriceTran]", ref error,
                    new SqlParameter("@trnNo", lblMaSo.Text),
                    new SqlParameter("@siteCode",Session["sitecode"].ToString()));
                if (kq)
                {
                    ShowMessageBox("Nghiệp vụ xác minh đổi giá thành công");
                }
                else
                {
                }

                LoadGrid();
            }
        }
        catch (Exception ex)
        {

            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            dt.WriteErrorLog(Server.MapPath(webapp4U.Globals.LogUrl()), ex.Message, method);
        }
    }
}